//
//  YYSLoginController.m
//  FanLaiWu
//
//  Created by gonglei on 17/3/17.
//  Copyright © 2017年 yys. All rights reserved.
//

#import "YYSLoginController.h"
#import "YYSRegisterController.h"
@interface YYSLoginController ()
@property (weak, nonatomic) IBOutlet UITextField *phoneText;
@property (weak, nonatomic) IBOutlet UITextField *passwordText;
@property (weak, nonatomic) IBOutlet UIButton *registerBtn;
@property (weak, nonatomic) IBOutlet UIButton *loginBtn;

@end

@implementation YYSLoginController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    
    self.registerBtn.layer.masksToBounds = YES;
    self.registerBtn.layer.cornerRadius = 5;
    self.loginBtn.layer.masksToBounds = YES;
    self.loginBtn.layer.cornerRadius = 5;

}
- (IBAction)backClick:(UIButton *)sender {
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
}
- (IBAction)forgetClick:(UIButton *)sender {
    YYSRegisterController *registe = [[YYSRegisterController alloc] init];
    registe.title = @"密码重置";
    [self presentViewController:registe animated:YES completion:^{
        
    }];
}
- (IBAction)registerClick:(UIButton *)sender {
    YYSRegisterController *registe = [[YYSRegisterController alloc] init];
    registe.title = @"注册";
    [self presentViewController:registe animated:YES completion:^{
        
    }];
}
- (IBAction)loginClick:(UIButton *)sender {
    if (_phoneText.text.length != 11) {
        
        [SVProgressHUD setMinimumDismissTimeInterval:1];
        [SVProgressHUD showErrorWithStatus:@"请输入正确手机号"];
        return;
    }
    if (_passwordText.text.length <= 0) {
        
        [SVProgressHUD setMinimumDismissTimeInterval:1];
        [SVProgressHUD showErrorWithStatus:@"请输入密码"];
        return;
    }
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    dict[@"mobile"] = _phoneText.text;
    dict[@"password"] = _passwordText.text;
    [NSObject POST:LOGIN_URL parameters:dict progress:^(NSProgress *downloadProgress) {
        
    } completionHandler:^(id responseObj, NSError *error) {
//        NSLog(@"%@",responseObj);
        if ([responseObj[@"errno"] integerValue] == 0) {
            [SVProgressHUD setMaximumDismissTimeInterval:2];
            [SVProgressHUD showSuccessWithStatus:@"登录成功"];
            [[SaveManager shareSaveManager] saveUserInfo:responseObj[@"result"]];
            [self dismissViewControllerAnimated:YES completion:^{
                
            }];
        } else {
            [SVProgressHUD showErrorWithStatus:responseObj[@"errmsg"]];
        }
    }];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
